<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('考试列表')" />
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="notice-form">
					<div class="select-list">
						<ul>
							<li>
								考试名称：<input type="text" name="title" autocomplete="off"/>
							</li>							
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm" id="toolbar" role="group">
		        <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="exam:exam:add">
		            <i class="fa fa-plus"></i> 新增
		        </a>
		        <!-- <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="exam:exam:edit">
		            <i class="fa fa-edit"></i> 修改
		        </a> -->
		        <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="exam:exam:remove">
		            <i class="fa fa-remove"></i> 删除
		        </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
	            <table id="bootstrap-table"></table>
	        </div>
    	</div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('exam:exam:edit')}]];
        var removeFlag = [[${@permission.hasPermi('exam:exam:remove')}]];
        var prefix = ctx + "exam/exam";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "考试",
                columns: [{
		            checkbox: true
		        },
				{
					field : 'id', 
					title : 'id',
					visible: false
				},
				{
					field : 'title', 
					title : '考试名称',
				},
				{
					field : 'timeLimit', 
					title : '考试时间',
					formatter: function(value, row, index) {
		            	if(value == 0){
		            		return '不限时'
		            	}
		            	return row.startTime+"~"+row.endTime
		            }
				},
				{
					field : 'totalTime', 
					title : '考试时长',
				},
				{
					field : 'maxCount', 
					title : '最大考试次数',
					formatter: function(value, row, index) {
						if(value == 0){
							return '不限次';
						}
						return value;
					}
				},
				{
					field : 'totalScore', 
					title : '考试总分'
				},
				{
					field : 'qualifyScore', 
					title : '及格线'
				},
				{
		            field: 'state',
		            title: '状态', 
		            formatter:function(value, row, index){
	            		if(value == 0){
	            			return "进行中";
	            		}
	            		if(value == 1){
	            			return "未发布";
	            		}
	            		if(value == 2){
	            			return "未开始";
	            		}
	            		if(value == 3){
	            			return "已结束";
	            		}
		            }
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	if(row.state == 1){
		            		actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
		            		actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="releaseExam(\'' + row.id + '\')"><i class="fa fa-edit"></i>发布</a> ');
		            	}
		            	if(row.state != 1){
		            		 actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="examPaperPre(\'' + row.id + '\')"><i class="fa fa-file-text-o"></i>试卷预览</a> ');
		            	}
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="examReport(\'' + row.id + '\')"><i class="fa fa-search"></i>统计分析</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
        function releaseExam(id){
        	if(!$.common.isEmpty(id)){
	       		$.modal.confirm("确定发布该考试吗？", function() {
	       			var url = prefix+"/release";
		            var data = { "id": id };
		            $.operate.submit(url, "post", "json", data);
	            })
        	}
        }
        function examReport(id){
        	var url = prefix+"/examReport/"+id;
        	$.modal.openTab("考试统计", url);
        }
        function examPaperPre(id){
        	var url=prefix+"/examPaperPre/"+id;
        	$.modal.openTab("试卷预览", url);
        }
    </script>
</body>
</html>